package edu.friday.repository;

import edu.friday.model.SysMenu;
import edu.friday.model.SysRole;
import edu.friday.repository.custom.SysMenuCustomRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

import java.util.List;

import static edu.friday.repository.SysRoleRepository.JOIN_USER;
import static edu.friday.repository.SysRoleRepository.JOIN_USER_ROLE;

@Repository
public interface SysMenuRepository extends JpaRepository<SysMenu,Long>, SysMenuCustomRepository {
    final String SELECT = " select distinct r.* from sys_role r ";
    @Query(value = SELECT + JOIN_USER_ROLE + JOIN_USER + "WHERE r.del_flag = '0' and ur.user_id = :userId ",
            nativeQuery = true)
    List<String> selectMenuPermsByUserId(@Param("userId") Long userId);


}
